import { combineReducers } from 'redux'
import theme from './theme'
import popular from './popular'
import trending from './trending'
import favorite from './favorite'
import { rootCom, RootNavigator } from '../navigator/AppNavigator'

//1.指定默认state
const navState = RootNavigator.router.getStateForAction(
	RootNavigator.router.getActionForPathAndParams(rootCom)
)

//2.创建自己的 navigation reducer
const navReducer = (state = navState, action) => {
	const nextState = RootNavigator.router.getStateForAction(action, state)
	//如果 nextState 为null或为定义，只需返回原始state
	return nextState || state
}

//3.合并reducer
const index = combineReducers({
	nav: navReducer,
	theme: theme,
	popular: popular,
	trending: trending,
	favorite: favorite
})

export default index
